package com.example.myapplication.network.api

import com.example.myapplication.network.core.RetrofitFactory
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.PUT
import retrofit2.http.Path

data class User(val id: Int,val name: String)

//专门处理User相关的网络请求接口
interface UserApiService {
    //接口地址：http://localhost:3000/users
    @GET("users")
    suspend fun getUsers(): List<User>

    //接口地址：http://localhost:3000/users
    @POST("users")
    suspend fun postUser(@Body user: User): Unit

    //接口地址：http://localhost:3000/users/1
    @PUT("users/{id}")
    suspend fun putUser(@Path("id") id: Int, @Body user: User)

    //接口地址：http://localhost:3000/users/2
    @DELETE("users/{id}")
    suspend fun deleteUser(@Path("id") id: Int)

    companion object{
        fun getInstance(): UserApiService {
            return RetrofitFactory.create(UserApiService::class.java)
        }
    }
}